﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace LevenBlog.Core.Utils
{
    public static class WebConfig
    {
        public static string BlogDbSetting {
            get {
                return ConfigurationManager.ConnectionStrings["BlogDbSetting"].ConnectionString;
            }
        }

        public static string ProviderName {
            get {
                return ConfigurationManager.ConnectionStrings["BlogDbSetting"].ProviderName;
            }
        }

        public static string PasswordKey {
            get {
                return ConfigurationManager.AppSettings["PasswordKey"];
            }
        }

        public static string PrefixKey {
            get {
                return ConfigurationManager.AppSettings["PrefixKey"];
            }
        }

        public static string AdminPasswordKey {
            get {
                return ConfigurationManager.AppSettings["AdminPasswordKey"];
            }
        }

        public static string ServiceCertificate {
            get {
                return ConfigurationManager.AppSettings["ServiceCertificate"];
            }
        }

        public static string ServiceCertificatePassword {
            get {
                return ConfigurationManager.AppSettings["ServiceCertificatePassword"];
            }
        }

        public static string ServiceUserName {
            get {
                return ConfigurationManager.AppSettings["ServiceUserName"];
            }
        }

        public static string ServicePassword {
            get {
                return ConfigurationManager.AppSettings["ServicePassword"];
            }
        }

        public static string ClientCertificate {
            get {
                return ConfigurationManager.AppSettings["ClientCertificate"];
            }
        }

        public static string ServiceUri {
            get {
                return ConfigurationManager.AppSettings["ServiceUri"];
            }
        }

        public static bool EnableServiceCertificate {
            get {
                bool result;
                if (!Boolean.TryParse(ConfigurationManager.AppSettings["EnableServiceCertificate"], out result)) {
                    result = false;
                }
                return result;
            }
        }

        static WebConfig()
        {
            //BlogDbSetting = ConfigurationManager.ConnectionStrings["BlogDbSetting"].ConnectionString;
            //ProviderName = ConfigurationManager.ConnectionStrings["BlogDbSetting"].ProviderName;
            //PasswordKey = ConfigurationManager.AppSettings["PasswordKey"];
            //if (string.IsNullOrEmpty(PasswordKey))
            //    PasswordKey = "levenblog";
            //if (PasswordKey.Length > 8)
            //    PasswordKey = PasswordKey.Substring(0, 8);
            //PrefixKey = ConfigurationManager.AppSettings["PrefixKey"];
            //if (string.IsNullOrEmpty(PrefixKey))
            //    PrefixKey = "levenblog";
            //ExtendName = ConfigurationManager.AppSettings["ExtendName"];
            //if (ExtendName == null)
            //    ExtendName = string.Empty;
            //AdminPasswordKey = ConfigurationManager.AppSettings["AdminPasswordKey"];
            //if (string.IsNullOrEmpty(AdminPasswordKey))
            //    AdminPasswordKey = "uyfs$^%43";
        }
    }
}
